/* eslint-disable @typescript-eslint/no-explicit-any */
/*
 *  Copyright 2021 Collate
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

 /**
 * TestConnection 是封装测试连接到特定服务所需步骤的定义
 */
export interface TestConnectionDefinition {
    /**
     * 导致此实体版本的更改
     */
    changeDescription?: ChangeDescription;
    /**
     * 当为 `true` 时表示实体已软删除
     */
    deleted?: boolean;
    /**
     * 测试连接定义的描述
     */
    description?: string;
    /**
     * 标识此测试定义的显示名称
     */
    displayName?: string;
    /**
     * 与 `name` 相同的 FullyQualifiedName
     */
    fullyQualifiedName?: string;
    /**
     * 指向与此实体对应的资源的链接
     */
    href?: string;
    /**
     * 此测试用例定义实例的唯一标识符
     */
    id?: string;
    /**
     * 测试连接定义的名称，应该是正在测试的服务的“type”，例如，Mysql 或 Snowflake
     */
    name: string;
    /**
     * 此 TestConnection 定义的所有者
     */
    owner?: EntityReference;
    /**
     * 测试连接的步骤，顺序很重要
     */
    steps: TestConnectionStep[];
    /**
     * 对应于实体新版本的上次更新时间，以 Unix 纪元时间毫秒表示
     */
    updatedAt?: number;
    /**
     * 进行更新的用户
     */
    updatedBy?: string;
    /**
     * 实体的元数据版本
     */
    version?: number;
}

/**
 * 导致此实体版本的更改
 *
 * Description of the change.
 */
export interface ChangeDescription {
    /**
     * Names of fields added during the version changes.
     */
    fieldsAdded?: FieldChange[];
    /**
     * Fields deleted during the version changes with old value before deleted.
     */
    fieldsDeleted?: FieldChange[];
    /**
     * Fields modified during the version changes with old and new values.
     */
    fieldsUpdated?: FieldChange[];
    /**
     * When a change did not result in change, this could be same as the current version.
     */
    previousVersion?: number;
}

export interface FieldChange {
    /**
     * Name of the entity field that changed.
     */
    name?: string;
    /**
     * New value of the field. Note that this is a JSON string and use the corresponding field
     * type to deserialize it.
     */
    newValue?: any;
    /**
     * Previous value of the field. Note that this is a JSON string and use the corresponding
     * field type to deserialize it.
     */
    oldValue?: any;
}

/**
 * 此 TestConnection 定义的所有者
 *
 * This schema defines the EntityReference type used for referencing an entity.
 * EntityReference is used for capturing relationships from one entity to another. For
 * example, a table has an attribute called database of type EntityReference that captures
 * the relationship of a table `belongs to a` database.
 */
export interface EntityReference {
    /**
     * If true the entity referred to has been soft-deleted.
     */
    deleted?: boolean;
    /**
     * Optional description of entity.
     */
    description?: string;
    /**
     * Display Name that identifies this entity.
     */
    displayName?: string;
    /**
     * Fully qualified name of the entity instance. For entities such as tables, databases
     * fullyQualifiedName is returned in this field. For entities that don't have name hierarchy
     * such as `user` and `team` this will be same as the `name` field.
     */
    fullyQualifiedName?: string;
    /**
     * Link to the entity resource.
     */
    href?: string;
    /**
     * Unique identifier that identifies an entity instance.
     */
    id: string;
    /**
     * If true the relationship indicated by this entity reference is inherited from the parent
     * entity.
     */
    inherited?: boolean;
    /**
     * Name of the entity instance.
     */
    name?: string;
    /**
     * Entity type/class name - Examples: `database`, `table`, `metrics`, `databaseService`,
     * `dashboardService`...
     */
    type: string;
}

/**
 * 测试服务的一个特定元素的功能，例如，列出模式、血缘或标签
 */
export interface TestConnectionStep {
    /**
     * 步骤的目标是什么
     */
    description: string;
    /**
     * 错误时在 UI 上显示的消息，我们在测试连接定义中手动定义此消息
     */
    errorMessage?: string;
    /**
     * 此步骤是否必须通过？
     */
    mandatory: boolean;
    /**
     * 被测试步骤的名称
     */
    name: string;
    /**
     * 如果设置为 true，则表示此步骤足够重要，以在失败时中断流程
     */
    shortCircuit?: boolean;
}
